<?php
/**
 * This class deals with Access Control Lists
 * @copyright inovia
 */  
class AccessRights{
	private $user;
	private $usergroup;
  private $groups;
  private $actions;
  
  /**
   * @todo switch for cache / flat php file / cache generation / php file generation
   */     
  public function __construct(){
    global $user;
    global $usergroup;
    $this->user       = &$user;
    $this->usergroup  = &$usergroup;
    include("rights.php");
    $this->groups  = $grps;
    $this->actions = $acts;
  
  }

  /**
   * Tells if the action is allowed to the group
   * @return bool true if allowed, false else   
   */     
  public function isActionAllowed($action){
    //if there is no restriction on the rights
    if($this->actions[$action] == '')     return true;
    if(isset($this->user->field->group))  return in_array($this->user->field->group,$this->actions[$action]);
    else                                  return in_array('',$this->actions[$action]);
  }
  
  /**
   * Initializes the userGroup instance if possible
   */     
  public function initUserGroup(){
  
    if($this->user != null){    
  		if(isset($this->user->field->group) &&  $this->user->field->group != ''){
  			$filename = "models/".$this->user->field->group.".php";
  		  if($this->user->field->group!=null && file_exists($filename)){
          include_once($filename);
          $constructor     = $this->user->field->group;
  		    $this->usergroup = new $constructor("rw","user",$this->user->field->user);
        }
      }
		}
  }
  
  /**
   * Tells if groupA inherits from groupB
   * @return bool true if inherits, false else
   */     
  public function inheritsFromGroup($groupA,$groupB){
    return in_array($groupA,$this->groups[$groupB]);
  }
}

?>
